package com.key.w8.common.execute;

import java.util.Stack;

/**
 * @Author: k8
 * @CreateTime: 2025-03-09
 * @Version: 1.0
 */
public abstract class ChainExecuteHandler{
    private ExecuteHandlerChain chain;
    private int index;

    /**
     * 交给责任链的下一个处理
     * @param msg
     * @param attach
     * @return
     */

    protected final Object fireNextHandler(Object msg, Object attach){
        ChainExecuteHandler next = chain.next(index + 1);
        if (next != null) return next.onInvoke(msg,attach);
        return null;
    }

    void setChain(ExecuteHandlerChain chain) {
        this.chain = chain;
    }

    void setIndex(int index) {
        this.index = index;
    }
    abstract public Object onInvoke(Object msg, Object attach);
}
